
class RegisterCheckbox extends Register {

  private CheckBox      mCheckBox;
  private Textlabel     mLabel; 
  private Numberbox     mNumValue;

  RegisterCheckbox( int pRegId, String pLabel, ControlP5 pCP5, int pX, int pY )
  {
    super( pRegId ); 

    int vLabelLength = pLabel.length() * 8;
    Toggle vToggle;

    this.mCheckBox = pCP5.addCheckBox( str(super.mRegId), pX + vLabelLength, pY );  
    this.mCheckBox.setItemsPerRow(8);
    this.mCheckBox.setSpacingColumn(40); 
    this.mCheckBox.setId(super.mRegId);


    for( int i = 0 ; i < 8; i++)
    {      
      vToggle = this.mCheckBox.addItem( super.mRegId + ":" + i, 1 );
      this.fixMargin( vToggle );
    }

    this.mLabel = pCP5.addTextlabel("label" + super.mRegId, pLabel, pX, pY);
    this.mLabel.setColorValue(gLabelColor);
    if( gUseC64Font )
    {
      this.mCheckBox.captionLabel().setControlFont( gC64Basic20 );
      this.mLabel.valueLabel().style().margin(-5, 0, 0, 0);
    }


    /*
    this.mNumValue = pCP5.addNumberbox("Value_" + super.mRegId, 0, pX + 520, pY, 30, 15);
     this.mNumValue.setMin( 0 );
     this.mNumValue.setMax( 255 );
     this.mNumValue.setId( 100 + super.mRegId );
     this.mNumValue.setDirection(Controller.HORIZONTAL);
     this.mNumValue.setDecimalPrecision( 0 );
     this.mNumValue.captionLabel().setVisible( false );
     this.mNumValue.valueLabel().style().margin( -6, 0, 0, 0 );
     */
  }


  public void updateCheckBox()
  {
    int vTmp = super.mValue;

    for(int i = 7; i >= 0; i--)
    {
      if( (vTmp & int(pow(2, i)) ) > 0 ) 
      {
        this.mCheckBox.activate(i);
        vTmp = vTmp - round(pow(2, i));
      }
      else
      {
        this.mCheckBox.deactivate(i);
      }
    }
  }

  // helper for c64 font
  private void fixMargin( Toggle vToggle )
  {
    if( gUseC64Font )
    {
      vToggle.captionLabel().style().moveMargin(-6, 0, 0, 0);
    }
  }
}

